gtk_css_calc_array_add (GPtrArray *array, GtkCssValue *value)
{
gsize i;
+ gint calc_term_order;
+
+ calc_term_order = gtk_css_number_value_get_calc_term_order (value);
for (i = 0; i < array->len; i++)
{
_gtk_css_value_unref (value);
return;
}
+ else if (gtk_css_number_value_get_calc_term_order (g_ptr_array_index (array, i)) > calc_term_order)
+ {
+ g_ptr_array_insert (array, i, value);
+ return;
+ }
}
g_ptr_array_add (array, value);
return NULL;
}
+static gint
+gtk_css_value_calc_get_calc_term_order (const GtkCssValue *value)
+{
+ /* This should never be needed because calc() can't contain calc(),
+ * but eh...
+ */
+ return 0;
+}
+
static const GtkCssNumberValueClass GTK_CSS_VALUE_CALC = {
{
gtk_css_value_calc_free,
gtk_css_value_calc_get_dimension,
gtk_css_value_calc_has_percent,
gtk_css_value_calc_multiply,
- gtk_css_value_calc_try_add
+ gtk_css_value_calc_try_add,
+ gtk_css_value_calc_get_calc_term_order
};
static GtkCssValue *
return gtk_css_dimension_value_new (value1->value + value2->value, value1->unit);
}
+static gint
+gtk_css_value_dimension_get_calc_term_order (const GtkCssValue *value)
+{
+ /* note: the order is alphabetic */
+ guint order_per_unit[] = {
+ /* [GTK_CSS_NUMBER] = */ 0,
+ /* [GTK_CSS_PERCENT] = */ 16,
+ /* [GTK_CSS_PX] = */ 11,
+ /* [GTK_CSS_PT] = */ 10,
+ /* [GTK_CSS_EM] = */ 3,
+ /* [GTK_CSS_EX] = */ 4,
+ /* [GTK_CSS_REM] = */ 13,
+ /* [GTK_CSS_PC] = */ 9,
+ /* [GTK_CSS_IN] = */ 6,
+ /* [GTK_CSS_CM] = */ 1,
+ /* [GTK_CSS_MM] = */ 7,
+ /* [GTK_CSS_RAD] = */ 12,
+ /* [GTK_CSS_DEG] = */ 2,
+ /* [GTK_CSS_GRAD] = */ 5,
+ /* [GTK_CSS_TURN] = */ 15,
+ /* [GTK_CSS_S] = */ 14,
+ /* [GTK_CSS_MS] = */ 8
+ };
+
+ return 1000 + order_per_unit[value->unit];
+}
+
static const GtkCssNumberValueClass GTK_CSS_VALUE_DIMENSION = {
{
gtk_css_value_dimension_free,
gtk_css_value_dimension_get_dimension,
gtk_css_value_dimension_has_percent,
gtk_css_value_dimension_multiply,
- gtk_css_value_dimension_try_add
+ gtk_css_value_dimension_try_add,
+ gtk_css_value_dimension_get_calc_term_order
};
GtkCssValue *
return number_value_class->try_add (value1, value2);
}
+/*
+ * gtk_css_number_value_get_calc_term_order:
+ * @value: Value to compute order for
+ *
+ * Determines the position of @value when printed as part of a calc()
+ * expression. Values with lower numbers are printed first. Note that
+ * these numbers are arbitrary, so when adding new types of values to
+ * print, feel free to change them in implementations so that they
+ * match.
+ *
+ * Returns: Magic value determining placement when printing calc()
+ * expression.
+ */
+gint
+gtk_css_number_value_get_calc_term_order (const GtkCssValue *value)
+{
+ GtkCssNumberValueClass *number_value_class = (GtkCssNumberValueClass *) value->class;
+
+ return number_value_class->get_calc_term_order (value);
+}
+
GtkCssValue *
_gtk_css_number_value_new (double value,
GtkCssUnit unit)
double factor);
GtkCssValue * (* try_add) (const GtkCssValue *value1,
const GtkCssValue *value2);
+ gint (* get_calc_term_order) (const GtkCssValue *value);
};
GtkCssValue * _gtk_css_number_value_new (double value,
GtkCssValue *value2);
GtkCssValue * gtk_css_number_value_try_add (const GtkCssValue *value1,
const GtkCssValue *value2);
+gint gtk_css_number_value_get_calc_term_order (const GtkCssValue *value);
double _gtk_css_number_value_get (const GtkCssValue *number,
double one_hundred_percent);
box-shadow.css \
box-shadow.ref.css \
calc.css \
+ calc.ref.css \
calc-simple.css \
calc-simple.ref.css \
close-at-end-of-file.css \
margin-left: calc(3px + 1em);
}
-a {
+b {
transition-duration: calc(1s - 100ms + -100ms);
}
+
+c {
+ margin-left: calc(-2px + 1em + 4px);
+}
+
+d {
+ background-size: calc( 100% - 10px );
+}
+
+e {
+ border-left-width: calc(1px + 1px);
+}
--- /dev/null
+a {
+ margin-left: calc(1em + 3px);
+}
+
+b {
+ transition-duration: calc(-200ms + 1s);
+}
+
+c {
+ margin-left: calc(1em + 2px);
+}
+
+d {
+ background-size: calc(-10px + 100%);
+}
+
+e {
+ border-left-width: 2px;
+}